package com.chenyao.bookstore.datahandler.impl;

import com.chenyao.bookstore.datahandler.IUserDataHandler;
import com.chenyao.bookstore.dataprovider.IUserDataProvider;
import com.chenyao.bookstore.dataprovider.impl.UserDataProviderImpl;
import com.chenyao.bookstore.entity.User;

public class UserDataHandlerImpl implements IUserDataHandler {
	private IUserDataProvider userDataProvider;

	public UserDataHandlerImpl() {
		this.userDataProvider = new UserDataProviderImpl();
	}

	@Override
	public User login(final User user) {
		User u = null;
		try {
			u = this.userDataProvider.find(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return u;
	}

	@Override
	public boolean register(final User user) {
		boolean regSuccess = false;
		try {
			if (null == this.userDataProvider.find(user))
				regSuccess = this.userDataProvider.save(user);
		} catch (Exception e) {
			e.printStackTrace();
			regSuccess = false;
		}

		return regSuccess;
	}
}
